using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

namespace shfa.snomtastic.data
{
    public partial class SqlDataProvider
    {

        public Guid InsertSetting(Guid categoryId, Guid subcategoryId, string name, int settingIndex, bool encrypted)
		{
            return new Guid(Convert.ToString(SqlHelper.ExecuteScalar(ConnectionString, "sp_SettingInsert", GetNull(categoryId), GetNull(subcategoryId), name, settingIndex, encrypted)));
		}

        public int UpdateSetting(Guid settingId, Guid categoryId, Guid subcategoryId, string name, int settingIndex, bool encrypted)
		{
            return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, "sp_SettingUpdate", GetNull(settingId), GetNull(categoryId), GetNull(subcategoryId), name, settingIndex, encrypted));
		}

        public int DeleteSetting(Guid settingId) 
		{
            return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, "sp_SettingDelete", settingId));
		}

        public DataRow SelectSetting(Guid settingId) 
        {    
			DataSet ds = SqlHelper.ExecuteDataset(ConnectionString, "sp_SettingSelect", settingId);
            if (ds.Tables.Count > 0)
                if (ds.Tables[0].Rows.Count > 0)
                    return ds.Tables[0].Rows[0];

            return null;
		}

		public DataTable SelectSettings() 
		{
            return SqlHelper.ExecuteDataset(ConnectionString, "sp_SettingSelectAll").Tables[0];
        }

		public DataTable SelectSettingsByCategory(Guid categoryId) 
		{
            return SqlHelper.ExecuteDataset(ConnectionString, "sp_SettingSelectByCategory", categoryId).Tables[0];
        }

		public DataTable SelectSettingsBySubcategory(Guid subcategoryId) 
		{
            return SqlHelper.ExecuteDataset(ConnectionString, "sp_SettingSelectBySubcategory", subcategoryId).Tables[0];
        }

    }

}
